package com.example.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author: 15489  <br/>
 * Date: 2022/3/24:11:34  <br/>
 * Description:
 */

@RestController
@RequestMapping("/kill")
public class KillController {
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/start")
    public boolean start(){
//        用老保存秒杀的结果 false表示失败 true表示成功
        boolean flag=false;

//        1：地区redis的库存
        int num=(Integer)redisTemplate.opsForValue().get("num");
//        2:判断库存
        if(num>0){
            num--;
            System.out.println("删减库存成功，还剩"+num);
//            修改redis的库存
            redisTemplate.opsForValue().set("num",num);
            flag=true;
        }
        return flag;
    }
}
